/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-12-20 10:02:11
 * @LastEditors: huangtianyang
 * @LastEditTime: 2024-01-26 17:28:43
 * @FilePath: \cxl-driving-training\src\views\system\protocol\previewDialog\index.ts
 */
import { getProtocolInformationById } from '@/apis/system/protocol'
import { reactive, ref } from 'vue'
import { channelEnum } from '../edit'
export class PreviewData {
    /**
     * 定义弹窗数据
     */
    dialog = reactive({
        visible: false,
        id: ''
    })

    /**
     * 协议内容
     */
    content = ref('')

    /**
     * 协议名称
     */
    name = ref('')

    /**
     * 协议渠道
     */
    channel = ref('')

    /**
     * 协议版本号
     */
    version = ref('')

    /**
     * 协议创建时间
     */
    time = ref('')

    /**
     * 通过协议id 获取协议内容
     * @param id
     */
    getProtocolById = (id: string) => {
        getProtocolInformationById(id).then(res => {
            if (Number(res.data.code) === 200) {
                this.content.value = res.data.result.content
                this.name.value = res.data.result.name
                const arr: string[] = []
                res.data.result.type.split(',').forEach((channel: number) => {
                    arr.push(channelEnum[channel])
                })
                this.channel.value = arr.join('、')
                this.version.value = res.data.result.version
                this.time.value = res.data.result.createTime

                console.log(this.name.value)
            }
        })
    }
}
